package com.contextor.magiccards.services.user.personage.impl;

import com.contextor.magiccards.dao.user.personage.PersonageDao;
import com.contextor.magiccards.model.character.Personage;
import com.contextor.magiccards.model.errors.dao.ObjectNotFoundException;
import com.contextor.magiccards.model.user.User;
import com.contextor.magiccards.services.BaseService;
import com.contextor.magiccards.services.user.personage.PersonageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * User: sergey
 * Date: Mar 22, 2011 12:22:48 PM
 */
@Service
class PersonageServiceImpl extends BaseService<Personage, PersonageDao> implements PersonageService {

    @Autowired
    public PersonageServiceImpl(PersonageDao dao) {
        super(dao);
    }

    public Personage loadByUser(User user) throws ObjectNotFoundException {
        final Personage personage = dao.loadByUser(user);
        if (personage == null) {
            throw new ObjectNotFoundException("userId=" + user.getId());
        }
        return personage;
    }

    public Personage loadByUser(int shard, User user) throws ObjectNotFoundException {
        return dao.loadByUser(user);
    }

    public Personage loadByUser(int shard, String userId) throws ObjectNotFoundException {
        return dao.loadByUserId(shard, userId);
    }
}
